<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<script type="text/javascript" src="js/jquery-3.2.0.js"></script>
<script type="text/javascript">

  $(function(){
	//添加
	  $("#save").click(function() {
			//$("form").serialize();
			var f = $("form")[0];//转换成dom对象

			var mydata = new FormData(f);
			$.ajax({
				url : "add.do",
				type : "POST",
				data : mydata,
				contentType : false,
				processData : false,
				success : function(d) {
					alert(d);
					f.reset();
				}
			});
			$(location).attr("href","students.html");
			return false;
	});
}); 

function PreviewImage(img) 
{ 
 var pattern = /(\.*.jpg$)|(\.*.png$)|(\.*.jpeg$)|(\.*.gif$)|(\.*.bmp$)/;      
 if(!pattern.test(img.value)) 
 { 
  alert("系统仅支持jpg/jpeg/png/gif/bmp格式的照片！");  
  img.focus(); 
 } 
 else 
 { 
  var path; 
  if(document.all)//IE 
  { 
   img.select(); 
   path = document.selection.createRange().text; 
   document.getElementById("imgPreview").innerHTML=""; 
   document.getElementById("imgPreview").style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled='true',sizingMethod='scale',src=\"" + path + "\")";//使用滤镜效果 
  } 
  else//FF 
  { 
   path = URL.createObjectURL(img.files[0]);
   document.getElementById("imgPreview").innerHTML = "<img src='"+path+"'/>"; 
  } 
 } 
} 

$(function(){
	 $("#telephone").blur(function(){
		 if(this.value==""){
			 return false;
		 }
		 $.get("checkTeleServlet",{tele:$(this).val()},function(data){
			 if(data=="true"){
 				  alert("此电话已经被注册了");
 			  }else{
 				  alert("此电话可以使用");
 			  }
		 },"text");
	 });
	 
	 $.get("GradeAllAjaxServlet",function(data){
		 var g=$("#gradeid");
		 $.each(data,function(i,d){
			 g.append(new Option(d.gname,d.id));
			 //g.append("<option value=''></option>");
		 });
	 });
});
</script>
</head>
<body>
<form action="#" method="post"  enctype="multipart/form-data">
<p>
	<label>学号</label>
	<input type="number" name="stuno" value="" />
</p>
<p>
	<label>姓名</label>
	<input type="text" name="sname" value="" />
</p>
<p>
	<label>性别</label>
	<input type="text" name="sex" value="" />
</p>
<p>
	<label>电话</label>
	<input type="number" name="telephone" value="" id="telephone"/><!-- onblur="checkTele(this)" -->
</p>
<p>
	<label>qq</label>
	<input type="number" name="qq" value="" />
</p>
<p>
	<label>微信</label>
	<input type="text" name="wechat" value="" />
</p>
<p>
	<label>年级编号</label>
			<select name="gradeid" id="gradeid">
				<option value=""></option>
				
			</select>
</p>
<p>
	<label>入学日期</label>
	<input type="text" name="enterdate" value="" />
</p>
<p>
	<label>来自哪里</label>
	<input type="text" name="fromcity" value="" />
</p>
<p>
	<label>出生日期</label>
	<input type="text" name="birthday" value="" />
</p>
<p>
	<label>地址</label>
	<input type="text" name="address" value="" />
</p>
<p>
	<label>密码</label>
	<input type="number" name="pass" value="" />
</p>
<p>
	<label>图片</label>
	<input type="file" name="pic" value="" onchange='PreviewImage(this)'/>
</p>
<div id="imgPreview" style='width:500px; height:400px;'> 
    		<img src=""/> 
   		</div> 
<p>
	<input type="submit" id="save" value="添加">
</p>
</form>
</body>
</html>